﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using GeoRef;

namespace GeoRef
{
    [TestFixture]
    public class GeoTripWhiteBoxTests
    {

        //+		start	{43.70998,10.398881}	GeoRef.GeoPoint
        //+		end	{43.782215,11.25431}	GeoRef.GeoPoint
        //+		pontedera	{43.666332,10.638223}	GeoRef.GeoPoint
        //+		empoli	{43.71871,10.947885}	GeoRef.GeoPoint

        GeoLoc p1, p2, p3, p4;
        GeoTrip trip;
        List<GeoLoc> vp;

        [SetUp]
        public void Init() {
            p1 = new GeoLoc(43.70998, 10.398881, "Pisa, Italy", "");
            p2 = new GeoLoc(43.782215, 11.25431, "Firenze, Italy", "");
            p3 = new GeoLoc(43.666332, 10.638223, "Pontedera, Italy", "");
            p4 = new GeoLoc(43.666332, 10.638223, "Empoli, Italy", "");

            trip = new GeoTrip(p1, p2);

            vp = new List<GeoLoc>();
            vp.Add(p3);
            vp.Add(p4);
        }

        #region GeoTrip constructor tests

        /// <summary>
        /// Tries to instance a new GeoTrip object with the same point
        /// for start and end; it should catch an ArgumentException 
        /// exception thrown by GeoRoute while GeoTrip tries to 
        /// instance the main route.
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentException))]
        public void TestConstructor1() {
            trip = new GeoTrip(p1, p1);
        }

        /// <summary>
        /// Tries to instance a new GeoTrip object with a void list of
        /// intermediate stops; it should catch an ArgumentNullException
        /// exception
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void TestConstructor2() {
            trip = new GeoTrip(p1, p2, new List<GeoLoc>());
        }

        /// <summary>
        /// Tries to insert a new stop in a route with negative index;
        /// it should catch an ArgumentOutOfRangeException exception.
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void TestInsertStop1() {
            trip.InsertStop(p3, -1);
        }
        /// <summary>
        /// Tries to insert a new stop in a route with index greater than
        /// the biggest actual index; it should catch an 
        /// ArgumentOutOfRangeException exception.
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void TestInsertStop2() {
            trip.InsertStop(p4, 5);
        }

        /// <summary>
        /// Tries to replace an existing route with a not well-formed pair 
        /// of new routes (the last point of the second new route is not 
        /// equal to the last point of the old route); it should catch an
        /// ArgumentException exception.
        /// </summary>
        [Test, ExpectedException(typeof(ArgumentException))]
        public void TestReplaceRoute() {
            GeoRoute r1 = new GeoRoute(p1, p3);
            GeoRoute r2 = new GeoRoute(p3, p4);
            trip.ReplaceRoute(r1, r2, 0);
        }

        #endregion

        #region GeoTrip Properties tests

        [Test]
        public void TestDistance() {
            Assert.AreEqual(trip.TotalDistance, 0);
            trip.UpdatePath();
            Assert.AreNotEqual(trip.TotalDistance, 0);
        }

        public void TestTime() {

        }

        #endregion
    }
}
